package com.baichuan.enums;


import com.baichuan.util.StringUtils;

/**
 * 文件上传类型枚举
 */
public enum FileUploadTypeEnum {


    /**
     * 轮播图
     */
    BANNER("banner", "banner/"),
    /**
     * 车辆档案
     */
    CAR_ARCHIVES("carArchives", "car/archives/"),
    /**
     * 车商LOGO
     */
    DEALER_LOGO("dealerLogo", "dealer/logo/"),
    /**
     * 车商资料图
     */
    DEALER_DATA("dealerData", "dealer/data/"),
    /**
     * 客户经理logo
     */
    CUST_MAGER_LOGO("custmagerLogo", "custmager/logo/"),
    /**
     * 客户经理二维码
     */
    CUST_MAGER_QRCODE("custmagerQrcode", "custmager/qrcode/"),
    /**
     * 客户经理logo
     */
    DEALER_USER_LOGO("dealerUserLogo", "dealer/user/logo/"),
    /**
     * 求购
     */
    WANT_BUY("wantBuy", "want/buy/"),
    /**
     * 拍卖
     */
    AUCTION("auction", "auction/"),
    /**
     * 报告
     */
    REPORT("report", "report/"),
    /**
     * 打电话录音
     */
    CALL_PHONE("callPhone", "callPhone/"),
    /**
     * 身份证
     */
    ID_CARD("idCard", "idCard/"),
    /**
     * 营业执照
     */
    BUSINESS_LICENSE("businessLicense", "businessLicense/"),
    /**
     * 营业执照
     */
    TEMPLATE_ICON("templateIcon", "templateIcon/"),

    /**
     * 海报照片
     */
    POSTER_ICON("posterIcon", "posterIcon/"),

    /**
     * 附件
     */
    ENCLOSURE("enclosure", "enclosure/"),

    /**
     * 附件图片
     */
    ENCLOSURE_ICON("enclosureIcon", "enclosureIcon/");


    /**
     * 文件代码
     */
    private final String uploadType;

    /**
     * 文件前缀
     */
    private final String uploadPrefix;


    private FileUploadTypeEnum(final String uploadType, final String uploadPrefix) {
        this.uploadType = uploadType;
        this.uploadPrefix = uploadPrefix;
    }

    public String getUploadType() {
        return uploadType;
    }

    public String getUploadPrefix() {
        return uploadPrefix;
    }


    public static String getFilePrefixByFileType(String uploadType) {
        if (StringUtils.isEmpty(uploadType)) {
            return null;
        }
        for (FileUploadTypeEnum e : FileUploadTypeEnum.values()) {
            if (uploadType.equals(e.uploadType)) {
                return e.uploadPrefix;
            }
        }
        return null;
    }

    public static FileUploadTypeEnum getByFileType(String uploadType) {
        if (StringUtils.isEmpty(uploadType)) {
            return null;
        }
        for (FileUploadTypeEnum e : FileUploadTypeEnum.values()) {
            if (uploadType.equals(e.uploadType)) {
                return e;
            }
        }
        return null;
    }
}